﻿using System;
using PPIDesktopClient.General;
using PPIDesktopClient.Logic;
using PPIDesktopClient.Presenter;

namespace PPIDesktopClient
{
    public partial class frmDownloadStats : frmDialogBase, IDownloadStats
    {
        public event EventHandler FinishDownload;
        private void OnFinishDownload(object o, EventArgs e)
        {
            // Safely invoke an event:
            if (FinishDownload != null)
            {
                FinishDownload(o, e);
            }
        }
        private DownloadStatsPresenter mPresenter;

        public frmDownloadStats()
        {
            InitializeComponent();

        }

        #region Control Events

        private void frmDownloadStats_Load(object sender, EventArgs e)
        {
            try
            {
                mPresenter = new DownloadStatsPresenter(this);
                this.Visible = true;
                if(OnLoad != null)
                    OnLoad(this,new EventArgs());
            }
            catch (Exception ex)
            {
                ErrorManager.Log("frmDownloadStats.frmDownloadStats_Load()", ex.Source, ex.Message, ex.StackTrace);
            }
        }

        
        private void btnHide_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if(this.StartDownload != null)
                this.StartDownload(this,new EventArgs());
            btnStop.Enabled = true;
            btnStart.Enabled = false;

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if(StopDownload!= null)
                StopDownload(this,new EventArgs());
            btnStop.Enabled = false;
            btnStart.Enabled = true;
        }

        private void chkVendor_CheckedChanged(object sender, EventArgs e)
        {
            chkUtility.Checked = false;
        }

        private void chkUtility_CheckedChanged(object sender, EventArgs e)
        {
            chkVendor.Checked = false;
        }


        #endregion

        #region IDownloadStats Members

        public bool UtilityCheck
        {
            get { return chkUtility.Checked; }
        }

        public bool VendorCheck
        {
            get { return chkVendor.Checked; }
        }

        public int ProgressBarValue
        {
            set { pbDownload.Value = value; }
        }

        public bool IsFinish
        {
            set
            {
                btnStop.Enabled = false;
                btnStart.Enabled = true;
                pbDownload.Value = 0;
            }
        }
        public int TotalImagesDesktop
        {
            set { lblnuTotalImagesDesktop.Text = value.ToString(); }
        }
        public int TotalImagesToDownload
        {
            set { lblnuTotalImagesServer.Text = value.ToString(); }
        }


        public event EventHandler<EventArgs> StartDownload;
        public event EventHandler<EventArgs> StopDownload;
        public new event EventHandler<EventArgs> OnLoad;

        #endregion


    }
}
